package com.xjtu.chapter08.thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author yjq
 * @version 1.0
 * @date 2021/9/1 11:10
 */
public class ExecutorTest {
    public static void main(String[] args) {
        //创建一个可调节大小的线程池
        ExecutorService pool_1 = Executors.newCachedThreadPool();

//        //创建一个单线程运行的线程池
//        ExecutorService pool_2 = Executors.newSingleThreadExecutor();
//        //创建一个可重复固定线程数的线程池
//        ExecutorService pool_3= Executors.newFixedThreadPool(5);
//        //创建一个可可重用固定线程数的线程池
//        ExecutorService pool_4= Executors.newScheduledThreadPool(1);

        //创建5个线程
        Thread thread_1 = new MyThread();
        Thread thread_2 = new MyThread();
        Thread thread_3 = new MyThread();
        Thread thread_4 = new MyThread();
        Thread thread_5 = new MyThread();

        //将线程放入线程池中进行执行
        pool_1.execute(thread_1);
        pool_1.execute(thread_2);
        pool_1.execute(thread_3);
        pool_1.execute(thread_4);
        pool_1.execute(thread_5);


    }
}
class MyThread extends Thread{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+" is running");
    }
}
